<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

class News extends Model
{
    use Searchable,HasFactory;

    protected $guarded = [];

    public function toSearchableArray(): array
    {
        return [
            'id' => (string) $this->id,
            'name' => $this->name,
            'content' => $this->content,
            'created_at' => $this->created_at->timestamp,
            'updated_at' => $this->updated_at->timestamp,
        ];
    }

    public function getTypesenseQueryParameters(): array
    {
        return [
            'query_by' => 'name,content',
        ];
    }

    /**
     * 获取与模型关联的索引的名称。
     */
    public function searchableAs(): string
    {
        return 'news_index';
    }
}
